package com.mszl.blog.controller;


import com.mszl.blog.common.aop.LogAnnotation;
import com.mszl.blog.common.cache.Cache;
import com.mszl.blog.service.ArticeService;
import com.mszl.blog.vo.ArticleVo;
import com.mszl.blog.vo.Result;
import com.mszl.blog.vo.params.ArticleParam;
import com.mszl.blog.vo.params.PageParams;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("articles")
public class ArticleController {
    @Autowired
    private ArticeService articeService;

    @PostMapping
    @LogAnnotation(module = "文章列表",operator = "获取文章列表")
    //@Cache(name = "文章列表")
    public Result listArticle(@RequestBody PageParams params){
        return articeService.listArticle(params);
    }

    @PostMapping("/hot")
    //@Cache(name = "hot_article")
    public Result hotArticle(){
        int limit=5;

        return articeService.hotArticle(limit);
    }
    @PostMapping("/new")
    //@Cache(name = "new_article")
    public Result newArticle(){
        int limit=5;
        return articeService.newArticle(limit);
    }
    /**
     * 首页 文章归档
     * @return
     */
    @PostMapping("listArchives")
    public Result listArchives(){
        return articeService.listArchives();
    }

    @PostMapping("view/{id}")
    public Result findArticleById(@PathVariable("id") Long id) {
        ArticleVo articleVo = articeService.findArticleById(id);

        return Result.success(articleVo);
    }

    @PostMapping("publish")
    public Result publish(@RequestBody ArticleParam articleParam){
        return articeService.publish(articleParam);
    }

    @PostMapping("search")
    public Result search(@RequestBody ArticleParam articleParam){
        String search = articleParam.getSearch();
        return articeService.search(search);
    }

    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable Long id){
        return articeService.deleteArticle(id);
    }






}
